package com.wlz.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wlz
 * @date 2022-06-29  10:56 下午
 */
@Configuration
public class RabbitMqConfig {

    /**
     * 定义交换机 的名称
     */
    public static final String EXCHANGE_NAME = "wlz_boot_topic_exchange";

    /**
     *  定义 队列的名称
     */
    public static final String QUEUE_NAME = "wlz_boot_queue";


    /**
     *  定义交换机
     * @return
     */
    @Bean("bootExchange")
    public Exchange bootExchange() {
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    /**
     *  声明队列
     * @return
     */
    @Bean("bootQueue")
    public Queue bootQueue() {
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    /**
     *  队列与交换机进行绑定
     * @return
     */
    @Bean
    public Binding bindQueueExchange() {
        return BindingBuilder.bind(bootQueue()).to(bootExchange()).with("wlz.boot.#").noargs();
    }

}
